﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Jumbot.Common;
using JumbotCms.API;
namespace JumbotCms.WebFile.Admin.Cut2Thumb
{
    public partial class _process : AdminCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ChannelId = Str2Str(q("ccid"));
            Admin_Load("", "html", true);
            if (!Page.IsPostBack)
            {
                string TempPhoto = q("tphoto");
                string ToWidth = q("tow");
                string ToHeight = q("toh");
                this.w.Text = this.tow.Value = ToWidth;
                this.h.Text = this.toh.Value = ToHeight;
                this.PhotoUrl.Value = TempPhoto;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int tow, toh, x, y, w, h;
            string file;
            tow = Convert.ToInt16(this.tow.Value.ToString());
            toh = Convert.ToInt16(this.toh.Value.ToString());
            x = Convert.ToInt16(this.x.Text);
            y = Convert.ToInt16(this.y.Text);
            w = Convert.ToInt16(this.w.Text);
            h = Convert.ToInt16(this.h.Text);

            file = Server.MapPath(this.PhotoUrl.Value.ToString());
            string fileExtension = ".jpg"; //缩略图后缀名
            string strXmlFile = HttpContext.Current.Server.MapPath("~/_data/config/upload_admin.config");
            Jumbot.DataOper.XmlControl XmlTool = new Jumbot.DataOper.XmlControl(strXmlFile);
            string sUserUploadPath = XmlTool.GetText("Module/" + ChannelType + "/path");
            XmlTool.Dispose();
            string DirectoryPath;

            DirectoryPath = site.Dir + ChannelDir + sUserUploadPath + "/" + DateTime.Now.ToString("yyyy-MM");
            Jumbot.Common.DirFile.CreateDir(site.Dir + ChannelDir + sUserUploadPath + "/" + DateTime.Now.ToString("yyyy-MM"));

            string sFileName = "thumb_" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + fileExtension;  // 文件名称
            string thumbnailPath = Server.MapPath(DirectoryPath + "/" + sFileName);        // 服务器端文件路径

            Jumbot.Common.ImageHelp.MakeMyThumbPhoto(file,thumbnailPath, tow, toh, x, y, w, h);
            WriteJs("-1", "parent.opener.document.getElementById('txtImg').value='" + DirectoryPath + "/" + sFileName + "';parent.close();");
        }

    }
}
